package com.fdb.efp.limit.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import com.fdb.efp.limit.service.dao.LmtPrelistSendRecordDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.limit.service.domain.LmtPrelistSendRecord;
import com.fdb.efp.limit.service.facade.LmtPrelistSendRecordService;
import com.fdb.efp.limit.service.vo.LmtPrelistSendRecordVO;

/**
 * <p>
 * 预授信名单信息发送记录表的Service实现类
 * </p>
 * @author szbd
 * @createDate 2018-07-17 15:45:42
 */
@Service("lmtPrelistSendRecordService")
public class LmtPrelistSendRecordServiceImpl implements LmtPrelistSendRecordService, FrameworkService {
    
    private static Logger logger = LoggerFactory.getLogger(LmtPrelistSendRecordServiceImpl.class);
    
    @Autowired
    private LmtPrelistSendRecordDao lmtPrelistSendRecordDao;
    
    @SuppressWarnings("unchecked")
	@Override
    public List<LmtPrelistSendRecordVO> queryAllOwnerByPage(LmtPrelistSendRecordVO inLmtPrelistSendRecordVo) {
        logger.info("查询本人所属的预授信名单信息发送记录表记录的请求参数为：" + JSONObject.toJSONString(inLmtPrelistSendRecordVo));
        if(Objects.isNull(inLmtPrelistSendRecordVo)){
            return null;
        }
        try {
            List<LmtPrelistSendRecord> dataList = lmtPrelistSendRecordDao.queryAllOwnerByPage(inLmtPrelistSendRecordVo);
            if (Objects.nonNull(dataList)) {
                List<LmtPrelistSendRecordVO> resultList = new ArrayList<LmtPrelistSendRecordVO>();
                resultList = (List<LmtPrelistSendRecordVO>) beansCopy(dataList, LmtPrelistSendRecordVO.class);
                return resultList;
            } else {
                logger.info("查询本人所属的预授信名单信息发送记录表记录为空！");
            }
        } catch (Exception e) {
            logger.error("查询本人所属的预授信名单信息发送记录表记录发生异常！", e);
        }
        return null;
    }
    
    @SuppressWarnings("unchecked")
	@Override
    public List<LmtPrelistSendRecordVO> queryAllCurrOrgByPage(LmtPrelistSendRecordVO inLmtPrelistSendRecordVo) {
        logger.info("查询本机构的预授信名单信息发送记录表记录的请求参数为：" + JSONObject.toJSONString(inLmtPrelistSendRecordVo));
        if(Objects.isNull(inLmtPrelistSendRecordVo)){
            return null;
        }
        try {
            List<LmtPrelistSendRecord> dataList = lmtPrelistSendRecordDao.queryAllCurrOrgByPage(inLmtPrelistSendRecordVo);
            if (Objects.nonNull(dataList)) {
                List<LmtPrelistSendRecordVO> resultList = new ArrayList<LmtPrelistSendRecordVO>();
                resultList = (List<LmtPrelistSendRecordVO>) beansCopy(dataList, LmtPrelistSendRecordVO.class);
                return resultList;
            } else {
                logger.info("查询本机构的预授信名单信息发送记录表记录为空！");
            }
        } catch (Exception e) {
            logger.error("查询本机构的预授信名单信息发送记录表记录发生异常！", e);
        }
        return null;
    }
    
    @SuppressWarnings("unchecked")
	@Override
    public List<LmtPrelistSendRecordVO> queryAllCurrDownOrgByPage(LmtPrelistSendRecordVO inLmtPrelistSendRecordVo) {
        logger.info("查询本机构及下属机构的预授信名单信息发送记录表记录的请求参数为：" + JSONObject.toJSONString(inLmtPrelistSendRecordVo));
        if(Objects.isNull(inLmtPrelistSendRecordVo)){
            return null;
        }
        try {
            List<LmtPrelistSendRecord> dataList = lmtPrelistSendRecordDao.queryAllCurrDownOrgByPage(inLmtPrelistSendRecordVo);
            if (Objects.nonNull(dataList)) {
                List<LmtPrelistSendRecordVO> resultList = new ArrayList<LmtPrelistSendRecordVO>();
                resultList = (List<LmtPrelistSendRecordVO>) beansCopy(dataList, LmtPrelistSendRecordVO.class);
                return resultList;
            } else {
                logger.info("查询本机构及下属机构的预授信名单信息发送记录表记录为空！");
            }
        } catch (Exception e) {
            logger.error("查询本机构及下属机构的预授信名单信息发送记录表记录发生异常！", e);
        }
        return null;
    }
    
    @Override
    public int insertLmtPrelistSendRecord(LmtPrelistSendRecordVO inLmtPrelistSendRecordVo) {
        logger.info("新增预授信名单信息发送记录表数据的参数为：" + JSONObject.toJSONString(inLmtPrelistSendRecordVo));
        if(Objects.isNull(inLmtPrelistSendRecordVo)){
            return 0;
        }
        int count = 0;
        try {
            LmtPrelistSendRecord lmtPrelistSendRecord = new LmtPrelistSendRecord();
            beanCopy(inLmtPrelistSendRecordVo, lmtPrelistSendRecord);
            count = lmtPrelistSendRecordDao.insertLmtPrelistSendRecord(lmtPrelistSendRecord);
        } catch (Exception e) {
            logger.error("新增预授信名单信息发送记录表数据发生异常！", e);
            count = -1;
        }
        logger.info("当前新增预授信名单信息发送记录表数据条数为：" + count);
        return count;
    }
    
    @Override
    public int deleteLmtPrelistSendRecordByPk(LmtPrelistSendRecordVO inLmtPrelistSendRecordVo) {
        logger.info("删除预授信名单信息发送记录表数据的参数为：" + JSONObject.toJSONString(inLmtPrelistSendRecordVo));
        if(Objects.isNull(inLmtPrelistSendRecordVo)){
            return 0;
        }
        int count = 0;
        try {
            LmtPrelistSendRecord lmtPrelistSendRecord = new LmtPrelistSendRecord();
            beanCopy(inLmtPrelistSendRecordVo, lmtPrelistSendRecord);
            count = lmtPrelistSendRecordDao.deleteLmtPrelistSendRecordByPk(lmtPrelistSendRecord);
        } catch (Exception e) {
            logger.error("删除预授信名单信息发送记录表数据发生异常！", e);
            count = -1;
        }
        logger.info("删除的预授信名单信息发送记录表数据条数为：" + count);
        return count;
    }
    
    @Override
    public int updateLmtPrelistSendRecordByPk(LmtPrelistSendRecordVO inLmtPrelistSendRecordVo) {
        logger.info("修改预授信名单信息发送记录表数据的参数为：" + JSONObject.toJSONString(inLmtPrelistSendRecordVo));
        if(Objects.isNull(inLmtPrelistSendRecordVo)){
            return 0;
        }
        int count = 0;
        try {
            LmtPrelistSendRecord lmtPrelistSendRecord = new LmtPrelistSendRecord();
            beanCopy(inLmtPrelistSendRecordVo, lmtPrelistSendRecord);
            count = lmtPrelistSendRecordDao.updateLmtPrelistSendRecordByPk(lmtPrelistSendRecord);
        } catch (Exception e) {
            logger.error("修改数据发生异常！", e);
            count = -1;
        }
        logger.info("修改的预授信名单信息发送记录表数据条数为" + count);
        return count;
    }
    
    @Override
    public LmtPrelistSendRecordVO queryLmtPrelistSendRecordByPk(LmtPrelistSendRecordVO inLmtPrelistSendRecordVo) {
        logger.info("根据主键查询预授信名单信息发送记录表的请求参数为：" + JSONObject.toJSONString(inLmtPrelistSendRecordVo));
        if(Objects.isNull(inLmtPrelistSendRecordVo)){
            return null;
        }
        try {
            LmtPrelistSendRecord lmtPrelistSendRecord = new LmtPrelistSendRecord();
            beanCopy(inLmtPrelistSendRecordVo, lmtPrelistSendRecord);
            lmtPrelistSendRecord = lmtPrelistSendRecordDao.queryLmtPrelistSendRecordByPk(lmtPrelistSendRecord);
            if (Objects.nonNull(lmtPrelistSendRecord)) {
                LmtPrelistSendRecordVO outLmtPrelistSendRecordVo = beanCopy(lmtPrelistSendRecord, new LmtPrelistSendRecordVO());
                return outLmtPrelistSendRecordVo;
            } else {
                logger.info("根据主键查询预授信名单信息发送记录表的记录为空！");
            }
        } catch (Exception e) {
            logger.error("根据主键查询预授信名单信息发送记录表记录发生异常！", e);
        }
        return null;
    }
    
    @Override
    public LmtPrelistSendRecordVO querySingleLmtPrelistSendRecordByCondition(LmtPrelistSendRecordVO inLmtPrelistSendRecordVo) {
        logger.info("根据条件查询单笔预授信名单信息发送记录表的请求参数为：" + JSONObject.toJSONString(inLmtPrelistSendRecordVo));
        if(Objects.isNull(inLmtPrelistSendRecordVo)){
            return null;
        }
        try {
            LmtPrelistSendRecord lmtPrelistSendRecord = new LmtPrelistSendRecord();
            beanCopy(inLmtPrelistSendRecordVo, lmtPrelistSendRecord);
            lmtPrelistSendRecord = lmtPrelistSendRecordDao.querySingleLmtPrelistSendRecordByCondition(lmtPrelistSendRecord);
            if (Objects.nonNull(lmtPrelistSendRecord)) {
                LmtPrelistSendRecordVO outLmtPrelistSendRecordVo = beanCopy(lmtPrelistSendRecord, new LmtPrelistSendRecordVO());
                return outLmtPrelistSendRecordVo;
            } else {
                logger.info("根据条件查询单笔预授信名单信息发送记录表的记录为空！");
            }
        } catch (Exception e) {
            logger.error("根据条件查询单笔预授信名单信息发送记录表记录发生异常！", e);
        }
        return null;
    }
    
    @SuppressWarnings("unchecked")
	@Override
    public List<LmtPrelistSendRecordVO> queryLmtPrelistSendRecordByCondition(LmtPrelistSendRecordVO inLmtPrelistSendRecordVo) {
        logger.info("条件查询预授信名单信息发送记录表的请求参数为：" + JSONObject.toJSONString(inLmtPrelistSendRecordVo));
        if(Objects.isNull(inLmtPrelistSendRecordVo)){
            return null;
        }
        try {
            List<LmtPrelistSendRecord> dataList = lmtPrelistSendRecordDao.queryLmtPrelistSendRecordByCondition(inLmtPrelistSendRecordVo);
            if (Objects.nonNull(dataList)) {
                List<LmtPrelistSendRecordVO> resultList = new ArrayList<LmtPrelistSendRecordVO>();
                resultList = (List<LmtPrelistSendRecordVO>) beansCopy(dataList, LmtPrelistSendRecordVO.class);
                return resultList;
            } else {
                logger.info("条件查询预授信名单信息发送记录表的数据为空！");
            }
        } catch (Exception e) {
            logger.error("条件查询预授信名单信息发送记录表发生异常！", e);
        }
        return null;
    }
    
    @SuppressWarnings("unchecked")
	@Override
    public List<LmtPrelistSendRecordVO> queryLmtPrelistSendRecordByConditionByPage(LmtPrelistSendRecordVO inLmtPrelistSendRecordVo) {
        logger.info("条件分页查询预授信名单信息发送记录表的请求参数为：" + JSONObject.toJSONString(inLmtPrelistSendRecordVo));
        if(Objects.isNull(inLmtPrelistSendRecordVo)){
            return null;
        }
        try {
            List<LmtPrelistSendRecord> dataList = lmtPrelistSendRecordDao.queryLmtPrelistSendRecordByConditionByPage(inLmtPrelistSendRecordVo);
            if (Objects.nonNull(dataList)) {
                List<LmtPrelistSendRecordVO> resultList = new ArrayList<LmtPrelistSendRecordVO>();
                resultList = (List<LmtPrelistSendRecordVO>) beansCopy(dataList, LmtPrelistSendRecordVO.class);
                return resultList;
            } else {
                logger.info("条件分页查询预授信名单信息发送记录表的数据为空！");
            }
        } catch (Exception e) {
            logger.error("条件分页查询预授信名单信息发送记录表发生异常！", e);
        }
        return null;
    }
    
    @Override
    public LmtPrelistSendRecordVO querySendRecordOfBizDate(LmtPrelistSendRecordVO inLmtPrelistSendRecordVo) {
        logger.info("根据主键查询预授信名单信息发送记录表的请求参数为：" + JSONObject.toJSONString(inLmtPrelistSendRecordVo));
        if(Objects.isNull(inLmtPrelistSendRecordVo)){
        	inLmtPrelistSendRecordVo = new LmtPrelistSendRecordVO();
        }
        try {
            LmtPrelistSendRecord lmtPrelistSendRecord = new LmtPrelistSendRecord();
            beanCopy(inLmtPrelistSendRecordVo, lmtPrelistSendRecord);
            lmtPrelistSendRecord = lmtPrelistSendRecordDao.querySendRecordOfBizDate(lmtPrelistSendRecord);
            if (Objects.nonNull(lmtPrelistSendRecord)) {
                LmtPrelistSendRecordVO outLmtPrelistSendRecordVo = beanCopy(lmtPrelistSendRecord, new LmtPrelistSendRecordVO());
                return outLmtPrelistSendRecordVo;
            } else {
                logger.info("根据主键查询预授信名单信息发送记录表的biz_date记录为空！");
            }
        } catch (Exception e) {
            logger.error("根据主键查询预授信名单信息发送记录表biz_date记录发生异常！", e);
        }
        return null;
    }
}